package com.nwl.crm.rest;

import com.nwl.crm.dto.PlatformDto;
import com.nwl.crm.dto.RoleDto;
import com.nwl.crm.service.PlatformService;
import com.nwl.crm.service.RoleService;
import com.nwl.crm.util.PageUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("roleRest")
public class RoleRest extends AbstractRest<RoleDto>{

    Logger logger = LoggerFactory.getLogger(RoleRest.class);

    @Autowired
    private RoleService service;

    @RequestMapping("getAll")
    public RoleDto getAll(RoleDto dto){
        try{
            service.getAll(dto);
        }catch (Exception e){
            logger.info(e.getMessage());
        }
        return dto;
    }

    @RequestMapping("layuiList")
    public PageUtil layuiList(RoleDto dto){
        try{
            PageUtil pageUtil = new PageUtil();
            dto.setPageUtil(pageUtil);
            int startIndex = (dto.getPage()-1)*dto.getLimit();
            dto.setStartIndex(startIndex);
            service.layuiList(dto);

            dto.getPageUtil().setCode(0);
        }catch (Exception e){
            e.printStackTrace();
            logger.info(e.getMessage());
            dto.getPageUtil().setCode(-1);
        }
        return dto.getPageUtil();
    }

    @RequestMapping("saveOrUpdate")
    public RoleDto saveOrUpdate(RoleDto dto){
        try{
            service.saveOrUpdate(dto);
        }catch (Exception e){
            e.printStackTrace();
            logger.info(e.getMessage());
        }
        return dto;
    }

    @RequestMapping("delete")
    public RoleDto delete(RoleDto dto){
        try{
            service.delete(dto);
        }catch (Exception e){
            e.printStackTrace();
            logger.info(e.getMessage());
        }
        return dto;
    }
}
